# -*- coding: utf-8 -*-

class Post:
    def __init__(self,id=None, title = None, user=None, time=None, link=None, content=None):
        self.postTitle = title
        self.postTime = time
        self.postID = id
        self.postUser = user
        self.postLink = link
        self.postContent = content
        self.data = {}
        
    def getID(self):
        return self.postID
    
    def getTitle(self):
        return self.postTitle
    
    def getUser(self):
        return self.postUser
    
    def getTime(self):
        return self.postTime
    
    def getLink(self):
        return self.postLink
    
    def getContent(self):
        return self.postContent

    def getData(self, tag):
        return self.data.get(tag)
    
    def setData(self, tag, value):
        self.data[tag] = value
        
class WatchArgs:
    MATCH_TYPE_AND = 1
    MATCH_TYPE_OR  = 0
    
    keywords = None
    matchType = MATCH_TYPE_OR
    ignoreCase = True
    contentMatch = False
    newPostMode = False
    themeMode = True
    
    def __init__(self):
        self.keywords = []
        self.matchType = WatchArgs.MATCH_TYPE_OR
        self.contentMatch = False
        
    def setKeywords(self, words):
        self.keywords = words
    
    def setMatchType(self, type):
        if type not in (WatchArgs.MATCH_TYPE_AND, WatchArgs.MATCH_TYPE_OR):
            return
        self.matchType = type
    
    def setIgnoreCase(self, ignore):
        self.ignoreCase = ignore
        
    def enableContentMatch(self, enable):
        self.contentMatch = enable
    
    def enableNewPostMode(self, enable):
        self.newPostMode = enable
    
    def enableThemeMode(self, enable):
        self.themeMode = enable

class Adapter:
    
    def __init__(self):
        pass
    
    def getPostList(self):
        return []
    
    def getPostDetail(self, Post):
        pass


class WatchConfig:
    def __init__(self, name, adapter, watchargs):
        self.name = name
        self.adapter = adapter
        self.watchargs = watchargs
        self.stopped = True
        
    def setName(self, name):
        self.name = name
      
    def setAdapter(self, adapter):
        self.adapter = adapter
  
    def setWatchArgs(self,args):
        self.watchargs = args

    def setStopped(self,stopped):
        self.stopped = stopped

    
    def __str__(self):
        if self.stopped:
            return u'%-60s[已停止]'%(self.name,)
        else:
            return u'%-60s[正在运行]'%(self.name,)

class MatchResult:
    def __init__(self, post, watchcfg):
        self.post = post
        self.config = watchcfg
    
    def __str__(self):
        return u'[%s] %s' %(self.config.name, self.post.getTitle())